package org.cloud.admin.auth.service.impl;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.cloud.admin.auth.service.AuthService;
import org.cloud.module.common.dao.SysUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * @author wangyuan
 * @since 2019年6月5日 下午6:54:38
 *
 */
@Service
public class AuthServiceImpl implements AuthService {
    
    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public Set<String> getUserPermissions(long userId) {
        List<String> permsList = sysUserDao.queryAllPerms(userId);
        //用户权限列表
        Set<String> permsSet = new HashSet<>();
        for(String perms : permsList){
            if(StringUtils.isBlank(perms)){
                continue;
            }
            permsSet.addAll(Arrays.asList(perms.trim().split(",")));
        }
        return permsSet;
    }
}
